{% extends 'layout/base.html' %}
{% load static %}

{% block css %}
    <link rel="stylesheet" href="{% static 'plugin/editor-md/css/editormd.min.css' %}">
    <style>
        .panel-default {
            margin-top: 10px;
        }

        .panel-default .panel-heading {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            font-size: 1.2rem;
        }

        .panel-body {
            padding: 0;
        }

        .title-list {
            border-right: 1px solid #dddddd;
            min-height: 500px;
        }

        .title-list ul {
            padding-left: 15px;
        }

        .title-list ul a {
            display: block;
            padding: 5px 0;
        }

        .content {
            border-left: 1px solid #dddddd;
            min-height: 600px;
            margin-top: 15px;
        }

        .red-msg{
            color: red;
        }

        .editormd-fullscreen {
            z-index: 2001;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div>
                    <i class="fa fa-book" aria-hidden="true"></i> wiki文档
                </div>
            </div>
            <div class="panel-body">
                <div class="col-sm-9 content">
                    <form method="post" novalidate>
                        {% csrf_token %}
                        {% for field in form %}
                            {% if field.name == "content" %}
                                <span class="red-msg">*</span>
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                <div id="editor">
                                    {{ field }}
                                </div>
                                <span class="red-msg">{{ field.errors.0 }}</span>
                            {% else %}
                                <div class="form-group">
                                    <span class="red-msg">*</span>
                                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                    {{ field }}
                                    <span class="red-msg">{{ field.errors.0 }}</span>
                                </div>
                            {% endif %}
                        {% endfor %}
                        <br/>
                        <button type="submit" class="btn btn-primary">提 交</button>
                    </form>
                </div>
                <div></div>
            </div>
        </div>
    </div>
{% endblock %}


{% block js %}
    <script src="{% static 'plugin/editor-md/editormd.min.js' %}"></script>
    <script>
        var WIKI_UPLOAD_URL = "{% url 'wiki_upload' %}";
        $(function () {
            initEditorMd();
        });

           /*
        初始化markdown编辑器（textare转换为编辑器）
         */
        function initEditorMd() {
            editormd('editor', {
                placeholder: "请输入内容",
                height: 550,
                path: "{% static 'plugin/editor-md/lib/' %}",
                // 图片
                imageUpload: true,
                imageFormats: ["jpg", 'jpeg', 'png', 'gif'],
                imageUploadURL: WIKI_UPLOAD_URL,
            })
        }

    
    
    </script>
    
{% endblock %}